Comparing administrative boundaries
Contents
3. Comparing administrative boundaries#
import sys, os, importlib, json, multiprocessing
import folium, shapely, rasterio
import pandas as pd
import geopandas as gpd
import numpy as np
from shapely.geometry import Polygon, Point, mapping
from shapely.ops import unary_union
from urllib.request import urlopen
sys.path.insert(0, "../../gostrocks/src/")
import GOSTRocks.ntlMisc as ntl
import GOSTRocks.rasterMisc as rMisc
from GOSTboundaries import boundary_helper
%load_ext autoreload
%autoreload 2
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
geobounds_url = 'https://www.geoboundaries.org/api/current/gbOpen/{iso3}/ADM{lvl}/'
sel_iso3 = 'VNM'
official_wb_bounds = f"/home/wb411133/projects/BOUNDARIES/Data/WB_med_res/{sel_iso3}_medium_res.geojson"
high_res_bounds = '/home/wb411133/projects/BOUNDARIES/Data/HighRes/WB_GAD_ADM_Samples/shp/WB_GAD_ADM2.shp'
output_folder = "/home/wb411133/projects/BOUNDARIES/"
# Open official World Bank boundaries
selWB = gpd.read_file(official_wb_bounds)
4. Run boundary comparison to Geobounds#
comparer = boundary_helper.country_boundary(sel_iso3, selWB)
xx = comparer.generate_boundary_difference(big_thresh=10000000)
comparer.generate_summary_difference()
comparer.map_corrected_bounds()
comparer.write_output(os.path.join(output_folder, "COUNTRY_RES", sel_iso3))
5. Run comparison between WB data at different resolutions#
inH = gpd.read_file(high_res_bounds)
selWB = selWB.to_crs(4326)
selH = inH.loc[inH['ISO_A3'] == sel_iso3]
comparer = boundary_helper.country_boundary(sel_iso3, selWB, geoBounds=selH)
xx = comparer.generate_boundary_difference(inGeo_id='OBJECTID')
m = comparer.map_corrected_bounds(geobounds_label='High def WB')
m
../src/boundary_helper.py:150: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
m = folium.Map(location=[selWB.centroid.y.values[0], selWB.centroid.x.values[0]], zoom_start=7, tiles="stamentoner", control_scale=True)
Make this Notebook Trusted to load map: File -> Trust Notebook